// pages/designerList/designerDetail.js
//获取应用实例
const app = getApp();
const api = require("../../utils/app1.js")
import Notify from '../../miniprogram_npm/@vant/weapp/notify/notify';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: '',
    isCk: '',
    brand: '',
    xinghao: '',
    count: '',
    sn: '',
    source: '',
    rukuData: '',
    makeS: '',
    quxiang: '',
    goku: '',
    makeQ: '',
    beizhu: '',
    id: 0,
    dialogHidden:true
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 调用监听器，监听数据变化
    app.watch(this, {
      id: function (newVal) {
        //请求去获取数据
        let url = "/ck/cklist/info/" + newVal
        console.log(url)

        api.getInfo(url).then(res => {
          let {
            name,
            isCk,
            brand,
            xinghao,
            count,
            sn,
            source,
            rukuData,
            makeS,
            quxiang,
            goku,
            makeQ,
            beizhu
          } = res.ckList
          this.setData({
            name,
            isCk,
            brand,
            xinghao,
            count,
            sn,
            source,
            rukuData,
            makeS,
            quxiang,
            goku,
            makeQ,
            beizhu
          });
        })
      }

    })


  },

  /**
   * 扫码事件
   */
  scanCodeEvent: function () {
    var that = this;
    wx.scanCode({
      onlyFromCamera: false, // 只允许从相机扫码
      success(res) {
        let id = res.result;
        console.log(id)
        that.setData({
          id: id
        })

      }
    })
  },

  closeTap: function () {
    var that = this;
    that.setData({
      dialogHidden: true,
    })
  },
  
  handSearch: function(){ 
    this.setData({
      dialogHidden:false
    })
  },

  formSubmit:function(e){
    var that = this;
        
    var value = e.detail.value;
    console.log(value)

    let url = "/ck/cklist/info/" + value.id
        api.getInfo(url).then(res => {
          let {
            id,name,isCk,brand,xinghao,count,sn,source,rukuData,makeS,quxiang,goku,makeQ,beizhu
          } = res.ckList
          that.setData({
            id,name,isCk,brand,xinghao,count,sn,source,rukuData,makeS,quxiang,goku,makeQ,beizhu
        })
        that.setData({
          dialogHidden: true,
        })
    })
  },


  //出库表单提交
  formchukuSubmit:function(e){
    var that = this;
    let id = that.data.id;  
    let isCk = "否";
    console.log(id) 
    var value = e.detail.value;
    let {quxiang,goku,makeQ,beizhu} = value
    let url = "/ck/cklist/update/"
    let data = {id,isCk,quxiang,goku,makeQ,beizhu}
    api.postInfo(url,data).then(res => {
      let url = "/ck/cklist/info/" + id
      Notify({
        type: 'success',
        message: '提交成功'
    })
        api.getInfo(url).then(res => {
          let {
            id,
            name,
            isCk,
            brand,
            xinghao,
            count,
            sn,
            source,
            rukuData,
            makeS,
            quxiang,
            goku,
            makeQ,
            beizhu
          } = res.ckList
          that.setData({
            id,
            name,
            isCk,
            brand,
            xinghao,
            count,
            sn,
            source,
            rukuData,
            makeS,
            quxiang,
            goku,
            makeQ,
            beizhu
          });      
        })
        that.setData({
          dialogHidden: true,
        })
      that.setData({
        dialogHidden: true,
      })
    })
    
  },

  //图片预览
  bindpreviewImage: function (e) {
    var that = this;
    console.log(e.currentTarget.id)
    var index = e.currentTarget.id;
    var picslist = that.data.designerDetail.pics;
    for (var i in picslist) {
      picslist[i] = that.data.urlhttp + picslist[i];
    }
    wx.previewImage({
      current: picslist[index], // 当前显示图片的http链接
      urls: picslist // 需要预览的图片http链接列表
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})